﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ImageProcessing.Forms
{
    public enum SlideShowSpeed { Slow, Medium, Fast };
    public enum SlideShowEffect { None, Greyscale, Sepia };
    public enum SlideShowTheme { Classic, Fade };
    public enum SlideShowBackGround { Color, Picture, Default };
    public partial class SlideShowOptions : Form
    {
        private SlideShowEffect effect;
        private SlideShowTheme theme;
        private SlideShowSpeed speed;
        private SlideShowBackGround bg;
        private Color bgClr;
        private string bgPath;
        private bool init;

        public SlideShowBackGround Bg
        {
            get { return bg; }
            set { bg = value; }
        }

        public Color BgClr
        {
            get { return bgClr; }
            set { bgClr = value; }
        }

        public string BgPath
        {
            get { return bgPath; }
            set { bgPath = value; }
        }

        public SlideShowEffect Effect
        {
            get { return effect; }
            set { effect = value; }
        }

        public SlideShowSpeed Speed
        {
            get { return speed; }
            set { speed = value; }
        }

        public SlideShowTheme Theme
        {
            get { return theme; }
            set { theme = value; }
        }

        public SlideShowOptions(SlideShowEffect sEffect, SlideShowTheme sTheme, SlideShowSpeed sSpeed,SlideShowBackGround sBg, Color bg)
        {
            InitializeComponent();
            init = true;
            this.Pnl_Color.BackColor = Color.Black;
            this.CenterTheForm();
            this.effect = sEffect;
            this.theme = sTheme;
            this.speed = sSpeed;
            this.bgClr = bg;
            this.bg = sBg;
            this.InitRads();
        }

        private void InitRads()
        {
            switch (effect)
            {
                case SlideShowEffect.None: this.Rad_None0.Checked = true; break;
                case SlideShowEffect.Greyscale: this.Rad_Greyscale1.Checked = true; break;
                case SlideShowEffect.Sepia: this.Rad_Sepia2.Checked = true; break;
            }
            switch (theme)
            {
                case SlideShowTheme.Classic: this.Rad_Classic0.Checked = true; break;
                case SlideShowTheme.Fade: this.Rad_Fade1.Checked = true; break;
            }
            switch (speed)
            {
                case SlideShowSpeed.Slow: this.Rad_Slow0.Checked = true; break;
                case SlideShowSpeed.Medium: this.Rad_Medium1.Checked = true; break;
                case SlideShowSpeed.Fast: this.Rad_Fast2.Checked = true; break;
            }
            switch (bg)
            {
                case SlideShowBackGround.Color: this.Rad_SolidColor0.Checked = true; this.Pnl_Color.BackColor = this.bgClr; break;
                case SlideShowBackGround.Picture: this.Rad_Picture1.Checked = true; break;
                case SlideShowBackGround.Default: this.Rad_Default2.Checked = true; break;
            }
            init = false;
        }

        private void groupBox1_Enter(object sender, EventArgs e)
        {

        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void label4_MouseEnter(object sender, EventArgs e)
        {
            this.label4.ForeColor = Color.Red;
        }

        private void label4_MouseLeave(object sender, EventArgs e)
        {
            this.label4.ForeColor = Color.White;
        }

        private void SlideShowOptions_Load(object sender, EventArgs e)
        {
            CenterTheForm();
        }

        private void panel1_Paint(object sender, PaintEventArgs e)
        {

        }

        private void panel2_Paint(object sender, PaintEventArgs e)
        {

        }

        private void label4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Rad_Fast2_CheckedChanged(object sender, EventArgs e)
        {
            string n = ((RadioButton)sender).Name;
            this.speed = (SlideShowSpeed)int.Parse(n[n.Length - 1] + string.Empty);
        }

        private void Rad_Classic0_CheckedChanged(object sender, EventArgs e)
        {
            string n = ((RadioButton)sender).Name;
            this.theme = (SlideShowTheme)int.Parse(n[n.Length - 1] + string.Empty);
        }

        private void Rad_None0_CheckedChanged(object sender, EventArgs e)
        {
            string n = ((RadioButton)sender).Name;
            this.effect = (SlideShowEffect)int.Parse(n[n.Length - 1] + string.Empty);
        }

        private void CenterTheForm()
        {
            int boundWidth = Screen.PrimaryScreen.Bounds.Width;
            int boundHeight = Screen.PrimaryScreen.Bounds.Height;
            this.Location = new Point((boundWidth / 2) - (this.Size.Width / 2), (boundHeight / 2) - (this.Size.Height / 2));
        }

        private void Pcb_BgPicture_Click(object sender, EventArgs e)
        {
            Rad_Picture1.Checked = true;
        }

        private void Pnl_Color_Paint(object sender, PaintEventArgs e)
        {

        }

        private void Pnl_Color_Click(object sender, EventArgs e)
        {
            if (Rad_SolidColor0.Checked && !init)
            {
                ColorDialog cDialog = new ColorDialog();
                Rad_SolidColor0.Checked = true;

                if (cDialog.ShowDialog() == DialogResult.OK)
                {
                    this.bgClr = cDialog.Color;
                    this.Pnl_Color.BackColor = this.bgClr;
                    this.bgPath = null;
                }
                else
                {
                    this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
                    this.bgClr = Color.FromArgb(1, 1, 1);
                    this.bgPath = null;
                }
                this.bg = SlideShowBackGround.Color;
            }
        }

        private void Rad_Picture1_CheckedChanged(object sender, EventArgs e)
        {
            //if (Rad_Picture1.Checked && !init)
            //{
            //    OpenFileDialog openFile = new OpenFileDialog();

            //    if (openFile.ShowDialog() == DialogResult.OK)
            //    {
            //        this.bgPath = openFile.FileName;
            //        this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
            //        this.bgClr = Color.FromArgb(1, 1, 1);
            //    }
            //    else
            //    {
            //        this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
            //        this.bgClr = Color.FromArgb(1, 1, 1);
            //        this.bgPath = null;
            //    }
            //    this.bg = SlideShowBackGround.Picture;


            //}
        }

        private void Rad_SolidColor0_CheckedChanged(object sender, EventArgs e)
        {
            this.bgClr = this.Pnl_Color.BackColor;
            this.bg = SlideShowBackGround.Color;
        }

        private void SlideShowOptions_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (!Rad_SolidColor0.Checked)
            {
                this.bgClr = Color.FromArgb(1, 1, 1);
            }
            if (!Rad_Picture1.Checked && !Rad_Default2.Checked)
            {
                this.bgPath = null;
            }
        }

        private void Rad_Picture1_Click(object sender, EventArgs e)
        {
            this.Rad_Picture1.Checked = true;
            OpenFileDialog openFile = new OpenFileDialog();

            if (openFile.ShowDialog() == DialogResult.OK)
            {
                this.bgPath = openFile.FileName;
                this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
                this.bgClr = Color.FromArgb(1, 1, 1);
            }
            else
            {
                this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
                this.bgClr = Color.FromArgb(1, 1, 1);
                this.bgPath = null;
            }
            this.bg = SlideShowBackGround.Picture;
        }

        private void Rad_Default2_CheckedChanged(object sender, EventArgs e)
        {
            if (Rad_Default2.Checked && !init)
            {
                this.bgPath = @"Icons\DefaultBackGround.jpg";
                this.Pnl_Color.BackColor = Color.FromArgb(1, 1, 1);
                this.bgClr = Color.FromArgb(1, 1, 1);
                this.bg = SlideShowBackGround.Default;
            }
        }
    }
}
